namespace SinaFinanceBaseClassLibrary.SinaFinanceService
{
    using System;
    using System.CodeDom.Compiler;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Runtime.CompilerServices;
    using System.ServiceModel;
    using System.ServiceModel.Channels;
    using System.Threading;

    [GeneratedCode("System.ServiceModel", "3.0.0.0"), DebuggerStepThrough]
    public class SinaFinanceServiceSoapClient : ClientBase<SinaFinanceServiceSoap>, SinaFinanceServiceSoap
    {
        private EventHandler<AsyncCompletedEventArgs> closeCompleted;
        private EventHandler<GetXmlCompletedEventArgs> getXmlCompleted;
        private ClientBase<SinaFinanceServiceSoap>.BeginOperationDelegate onBeginCloseDelegate;
        private ClientBase<SinaFinanceServiceSoap>.BeginOperationDelegate onBeginGetXmlDelegate;
        private ClientBase<SinaFinanceServiceSoap>.BeginOperationDelegate onBeginOpenDelegate;
        private SendOrPostCallback onCloseCompletedDelegate;
        private ClientBase<SinaFinanceServiceSoap>.EndOperationDelegate onEndCloseDelegate;
        private ClientBase<SinaFinanceServiceSoap>.EndOperationDelegate onEndGetXmlDelegate;
        private ClientBase<SinaFinanceServiceSoap>.EndOperationDelegate onEndOpenDelegate;
        private SendOrPostCallback onGetXmlCompletedDelegate;
        private SendOrPostCallback onOpenCompletedDelegate;
        private EventHandler<AsyncCompletedEventArgs> openCompleted;

        public event EventHandler<AsyncCompletedEventArgs> CloseCompleted
        {
            [MethodImpl(MethodImplOptions.Synchronized)] add
            {
                this.openCompleted = (EventHandler<AsyncCompletedEventArgs>)Delegate.Combine((Delegate)this.openCompleted, (Delegate)value);
            }
            [MethodImpl(MethodImplOptions.Synchronized)] remove
            {
                this.openCompleted = (EventHandler<AsyncCompletedEventArgs>)Delegate.Remove((Delegate)this.openCompleted, (Delegate)value);
            }
        }

        public event EventHandler<GetXmlCompletedEventArgs> GetXmlCompleted
        {
            [MethodImpl(MethodImplOptions.Synchronized)] add
            {
                this.getXmlCompleted = (EventHandler<GetXmlCompletedEventArgs>) Delegate.Combine((Delegate) this.getXmlCompleted, (Delegate) value);
            }
            [MethodImpl(MethodImplOptions.Synchronized)] remove
            {
                this.getXmlCompleted = (EventHandler<GetXmlCompletedEventArgs>) Delegate.Remove((Delegate) this.getXmlCompleted, (Delegate) value);
            }
        }

        public event EventHandler<AsyncCompletedEventArgs> OpenCompleted
        {
            [MethodImpl(MethodImplOptions.Synchronized)] add
            {
                this.openCompleted = (EventHandler<AsyncCompletedEventArgs>) Delegate.Combine((Delegate) this.openCompleted, (Delegate) value);
            }
            [MethodImpl(MethodImplOptions.Synchronized)] remove
            {
                this.openCompleted = (EventHandler<AsyncCompletedEventArgs>) Delegate.Remove((Delegate) this.openCompleted, (Delegate) value);
            }
        }

        public SinaFinanceServiceSoapClient()
        {
        }

        public SinaFinanceServiceSoapClient(string endpointConfigurationName) : base(endpointConfigurationName)
        {
        }

        public SinaFinanceServiceSoapClient(Binding binding, EndpointAddress remoteAddress) : base(binding, remoteAddress)
        {
        }

        public SinaFinanceServiceSoapClient(string endpointConfigurationName, EndpointAddress remoteAddress) : base(endpointConfigurationName, remoteAddress)
        {
        }

        public SinaFinanceServiceSoapClient(string endpointConfigurationName, string remoteAddress) : base(endpointConfigurationName, remoteAddress)
        {
        }

        [EditorBrowsable(EditorBrowsableState.Advanced)]
        private IAsyncResult BeginGetXml(string StrUrl, AsyncCallback callback, object asyncState)
        {
            GetXmlRequest request = new GetXmlRequest {
                Body = new GetXmlRequestBody()
            };
            request.Body.StrUrl = StrUrl;
            return ((SinaFinanceServiceSoap) this).BeginGetXml(request, callback, asyncState);
        }

        public void CloseAsync()
        {
            this.CloseAsync(null);
        }

        public void CloseAsync(object userState)
        {
            if (this.onBeginCloseDelegate == null)
            {
                this.onBeginCloseDelegate = new ClientBase<SinaFinanceServiceSoap>.BeginOperationDelegate(this.OnBeginClose);
            }
            if (this.onEndCloseDelegate == null)
            {
                this.onEndCloseDelegate = new ClientBase<SinaFinanceServiceSoap>.EndOperationDelegate(this.OnEndClose);
            }
            if (this.onCloseCompletedDelegate == null)
            {
                this.onCloseCompletedDelegate = new SendOrPostCallback(this.OnCloseCompleted);
            }
            base.InvokeAsync(this.onBeginCloseDelegate, null, this.onEndCloseDelegate, this.onCloseCompletedDelegate, userState);
        }

        protected override SinaFinanceServiceSoap CreateChannel()
        {
            return new SinaFinanceServiceSoapClientChannel(this);
        }

        [EditorBrowsable(EditorBrowsableState.Advanced)]
        private string EndGetXml(IAsyncResult result)
        {
            return ((SinaFinanceServiceSoap) this).EndGetXml(result).Body.GetXmlResult;
        }

        public void GetXmlAsync(string StrUrl)
        {
            this.GetXmlAsync(StrUrl, null);
        }

        public void GetXmlAsync(string StrUrl, object userState)
        {
            if (this.onBeginGetXmlDelegate == null)
            {
                this.onBeginGetXmlDelegate = new ClientBase<SinaFinanceServiceSoap>.BeginOperationDelegate(this.OnBeginGetXml);
            }
            if (this.onEndGetXmlDelegate == null)
            {
                this.onEndGetXmlDelegate = new ClientBase<SinaFinanceServiceSoap>.EndOperationDelegate(this.OnEndGetXml);
            }
            if (this.onGetXmlCompletedDelegate == null)
            {
                this.onGetXmlCompletedDelegate = new SendOrPostCallback(this.OnGetXmlCompleted);
            }
            base.InvokeAsync(this.onBeginGetXmlDelegate, new object[] { StrUrl }, this.onEndGetXmlDelegate, this.onGetXmlCompletedDelegate, userState);
        }

        private IAsyncResult OnBeginClose(object[] inValues, AsyncCallback callback, object asyncState)
        {
            return null;
            //return this. BeginClose(callback, asyncState);
        }

        private IAsyncResult OnBeginGetXml(object[] inValues, AsyncCallback callback, object asyncState)
        {
            string strUrl = (string) inValues[0];
            return this.BeginGetXml(strUrl, callback, asyncState);
        }

        private IAsyncResult OnBeginOpen(object[] inValues, AsyncCallback callback, object asyncState)
        {
            return null;
            //return this.BeginOpen(callback, asyncState);
        }

        private void OnCloseCompleted(object state)
        {
            if (this.closeCompleted != null)
            {
                ClientBase<SinaFinanceServiceSoap>.InvokeAsyncCompletedEventArgs args = (ClientBase<SinaFinanceServiceSoap>.InvokeAsyncCompletedEventArgs) state;
                this.closeCompleted(this, new AsyncCompletedEventArgs(args.Error, args.Cancelled, args.UserState));
            }
        }

        private object[] OnEndClose(IAsyncResult result)
        {
            //this.EndClose(result);
            return null;
        }

        private object[] OnEndGetXml(IAsyncResult result)
        {
            string str = this.EndGetXml(result);
            return new object[] { str };
        }

        private object[] OnEndOpen(IAsyncResult result)
        {
            //this.EndOpen(result);
            return null;
        }

        private void OnGetXmlCompleted(object state)
        {
            if (this.getXmlCompleted != null)
            {
                ClientBase<SinaFinanceServiceSoap>.InvokeAsyncCompletedEventArgs args = (ClientBase<SinaFinanceServiceSoap>.InvokeAsyncCompletedEventArgs) state;
                this.getXmlCompleted(this, new GetXmlCompletedEventArgs(args.Results, args.Error, args.Cancelled, args.UserState));
            }
        }

        private void OnOpenCompleted(object state)
        {
            if (this.openCompleted != null)
            {
                ClientBase<SinaFinanceServiceSoap>.InvokeAsyncCompletedEventArgs args = (ClientBase<SinaFinanceServiceSoap>.InvokeAsyncCompletedEventArgs) state;
                this.openCompleted(this, new AsyncCompletedEventArgs(args.Error, args.Cancelled, args.UserState));
            }
        }

        public void OpenAsync()
        {
            this.OpenAsync(null);
        }

        public void OpenAsync(object userState)
        {
            if (this.onBeginOpenDelegate == null)
            {
                this.onBeginOpenDelegate = new ClientBase<SinaFinanceServiceSoap>.BeginOperationDelegate(this.OnBeginOpen);
            }
            if (this.onEndOpenDelegate == null)
            {
                this.onEndOpenDelegate = new ClientBase<SinaFinanceServiceSoap>.EndOperationDelegate(this.OnEndOpen);
            }
            if (this.onOpenCompletedDelegate == null)
            {
                this.onOpenCompletedDelegate = new SendOrPostCallback(this.OnOpenCompleted);
            }
            base.InvokeAsync(this.onBeginOpenDelegate, null, this.onEndOpenDelegate, this.onOpenCompletedDelegate, userState);
        }

        [EditorBrowsable(EditorBrowsableState.Advanced)]
        IAsyncResult SinaFinanceServiceSoap.BeginGetXml(GetXmlRequest request, AsyncCallback callback, object asyncState)
        {
            return base.Channel.BeginGetXml(request, callback, asyncState);
        }

        [EditorBrowsable(EditorBrowsableState.Advanced)]
        GetXmlResponse SinaFinanceServiceSoap.EndGetXml(IAsyncResult result)
        {
            return base.Channel.EndGetXml(result);
        }

        private class SinaFinanceServiceSoapClientChannel : ClientBase<SinaFinanceServiceSoap>.ChannelBase<SinaFinanceServiceSoap>, SinaFinanceServiceSoap
        {
            public SinaFinanceServiceSoapClientChannel(ClientBase<SinaFinanceServiceSoap> client) : base(client)
            {
            }

            public IAsyncResult BeginGetXml(GetXmlRequest request, AsyncCallback callback, object asyncState)
            {
                object[] objArray = new object[] { request };
                return base.BeginInvoke("GetXml", objArray, callback, asyncState);
            }

            public GetXmlResponse EndGetXml(IAsyncResult result)
            {
                object[] objArray = new object[0];
                return (GetXmlResponse) base.EndInvoke("GetXml", objArray, result);
            }
        }
    }
}
